package au.com.centrumsystems.hudson.plugin.buildpipeline;

import java.util.HashMap;
import java.util.Map;

/**
 * @author <a href="mailto:nicolas.deloof@cloudbees.com">Nicolas De loof</a>
 */
public class ProjectGrid extends Grid<ProjectForm> {

    /**
     * Gets a display value to determine whether a manual jobs 'trigger' button
     * will be shown.  This is used along with isTriggerOnlyLatestJob property
     * allow only the latest version of a job to run.
     *
     * Works by:
     * Initially always defaulted to true.
     * If isTriggerOnlyLatestJob is set to true then as the html code is rendered the first
     * job which should show the trigger button will render and then a call will be made
     * to 'setDisplayTrigger' to change the value to both so all future jobs will
     * not display the trigger.  see main.jelly
     *
     * @param row the row of the job
     * @param height the height of the job
     * @return boolean whether to display or not
     */
    public Boolean getDisplayTrigger(int row, int height) {
        return get(row, height).getDisplayTrigger();
    }

    /**
     * Sets a display value to determine whether a manual jobs 'trigger' button
     * will be shown.  This is used along with isTriggerOnlyLatestJob property
     * allow only the latest version of a job to run.
     *
     * Works by:
     * Initially always defaulted to true.
     * If isTriggerOnlyLatestJob is set to true then as the html code is rendered the first
     * job which should show the trigger button will render and then a call will be made
     * to 'setDisplayTrigger' to change the value to both so all future jobs will
     * not display the trigger.  see main.jelly

     * @param row the row of the job
     * @param height the height of the job
     * @param display - boolean to indicate whether the trigger button should be shown
     */
    public void setDisplayTrigger(int row, int height, boolean display) {
        get(row, height).setDisplayTrigger(display);
    }

    @Override
    protected final Map<Integer, ProjectForm> newRow() {
        return new HashMap<Integer, ProjectForm>();
    }

}
